package com.shitao.forum.controller;

import com.shitao.forum.common.AppResult;
import com.shitao.forum.exception.ApplicationException;
import com.shitao.forum.model.Article;
import com.shitao.forum.model.Board;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags= "测试类相关接口") // 作用在类上的，对控制器进行的说明
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，返回hello world")
    @GetMapping("/hello")
    public String hello() {
        return "hello spring";
    }

    @ApiOperation("测试接口4,按传入字段进行返回")
    @PostMapping("hello2")
    public String hello2(@ApiParam(value = "姓名") @RequestParam("name") String name) {
        return "hello" + name;
    }

    @ApiOperation("测试接口2，显示异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("异常！！！！！！！");
    }
    @ApiOperation("测试接口3，显示自定义异常信息")
    @GetMapping("/applicationException")
    public AppResult testApplicationException() {
        throw new ApplicationException("Application异常！！！！！");
    }

    @RequestMapping("/init")
    public String init() {
        return "执行了init方法";
    };
}
